import { Controller, Get, Query } from '@nestjs/common';
import { EatyetService } from './eatyet.service';
import { BaseResult } from '../entity/dto/base.dto';

@Controller('eatyet')
export class EatyetController {
  constructor(private readonly eatyetService: EatyetService) {}

  @Get('random')
  async random(@Query('size') size: number) {
    let query: any[] = [];
    for (let i = 0; i < size; i++) {
      query.push(this.eatyetService.random());
    }
    let result = await Promise.allSettled([...query]);
    return BaseResult.success(
      result.map((e) => e['value']).filter((e) => e !== null),
    );
  }
}
